package com.jshcbd.mvp_kt_demo.app

import android.app.Activity
import android.app.Application
import android.content.Context
import com.jshcbd.mvp_kt_demo.utils.LogUtil
import com.tencent.mmkv.MMKV

/**
 * Created by zzt
 * 2021/8/18
 */
class  MyApplication : Application() {

    companion object {
        /*** 项目全局上下文  */

        var application: MyApplication? = null

        private var activityList = mutableListOf<Activity>()

        /**
         * 添加activity
         */
        fun addActivity(activity: Activity) {
            activityList.add(activity)
        }

        /**
         * 移除activity
         */
        fun removeActivity(activity: Activity) {
            if (activityList.contains(activity)) {
                activity.finish()
                activityList.remove(activity)
            }
        }
        /**
         * 获取所有存在的activity
         */
        fun getActivities(): MutableList<Activity> {
            return activityList
        }

        /**
         * 退出登录
         */
        fun exitLogin() {
            for (ac in activityList) {
                removeActivity(ac)
            }
        }
    }


    override fun onCreate() {
        super.onCreate()
        application = this
        //初始化MMKV
        MMKV.initialize(this)
        // 初始化Looger工具
        LogUtil.init(true)
    }
}